<template>
  <div class="posts" @click="$router.push('/postDetail/' + post.id)">
    <!-- 情况1：小于三张图片 -->
    <div class="onePic" v-if="post.type===1 && post.cover.length<3  && post.cover.length>=1">
      <div class="onePic_left">
        <div class="onePic_left_title">{{ post.title }}</div>

        <div class="onePic_left_msg">
          <span>{{ post.user.nickname }}</span>
          <span>{{ commentNum }}跟帖</span>
        </div>
      </div>

      <img :src="post.cover[0].url" alt class="pic" />
    </div>

    <!-- 情况2；大于等于三张图片 -->
    <div class="threePic" v-if="post.type===1 && post.cover.length>=3">
      <div class="title">{{ post.title }}</div>

      <div class="pic">
        <img :src="post.cover[0].url" alt />
        <img :src="post.cover[1].url" alt />
        <img :src="post.cover[2].url" alt />
      </div>

      <div class="msg">
        <span>{{ post.user.nickname }}</span>
        <span>{{ commentNum }}跟帖</span>
      </div>
    </div>

    <!-- 情况3：视频 -->
    <div class="video" v-if="post.type===2 && post.cover.length>=1">
      <div class="title">{{ post.title }}</div>

      <div class="pic">
        <img :src="post.cover[0].url" alt />
        <div class="iconfont iconshipin"></div>
      </div>

      <div class="msg">
        <span>{{ post.user.nickname }}</span>
        <span>{{ commentNum }}跟帖</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["post"],
  computed: {
    commentNum(){
      if(this.post.comment_length){
        return this.post.comment_length
      }else if(this.post.comment_length===0){
        return 0;
      }else{
        return this.post.comments.length
      }
    }
  }
};
</script>

<style lang="less" scoped>
// 情况1：小于三张图片
.onePic {
  display: flex;
  // justify-content: space-around;
  padding: 3.889vw 2.778vw;
  border-bottom: 0.278vw solid #eee;

  .onePic_left {
    flex: 1;
    padding: 0 2.222vw;
    position: relative;

    .onePic_left_title {
      font-size: 3.889vw;
      line-height: 6.667vw;
    }

    .onePic_left_msg {
      position: absolute;
      font-size: 3.333vw;
      bottom: 3.333vw;
      color: #929292;

      span {
        padding-right: 1.667vw;
      }
    }
  }

  .pic {
    width: 40vw;
    height: 25vw;
    object-fit: cover;
  }
}

// 情况2；大于等于三张图片
.threePic {
  padding: 2.778vw 2.778vw;
  border-bottom: 0.278vw solid #eee;
  box-sizing: border-box;

  .title {
    font-size: 3.889vw;
    line-height: 6.667vw;
  }

  .pic {
    display: flex;

    img {
      width: 33%;
      margin-right: 0.556vw;
      object-fit: cover;
    }
  }

  .msg {
    font-size: 3.333vw;
    bottom: 3.333vw;
    color: #929292;
    padding-top: 1.111vw;

    span {
      padding-right: 1.667vw;
    }
  }
}

// 情况3：视频
.video {
  padding: 3.889vw 2.778vw;
  border-bottom: 0.278vw solid #eee;

  .title {
    font-size: 3.889vw;
    line-height: 6.667vw;
  }

  .pic {
    position: relative;

    img {
      width: 100%;
      object-fit: cover;
      padding-top: 1.111vw;
    }

    .iconshipin {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-size: 16.667vw;
      color: rgba(255, 255, 255, .8);
    }
  }

  .msg {
    font-size: 3.333vw;
    bottom: 3.333vw;
    color: #929292;
    padding-top: 1.111vw;

    span {
      padding-right: 1.667vw;
    }
  }
}
</style>